import { reactive } from "vue";
import { useUserStore } from "@/stores/modules/user.ts";
/** 密码正则（密码格式应为8-18位数字、字母、符号的任意两种组合） */
export const REGEXP_PWD =
  /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[()])+$)(?!^.*[\u4E00-\u9FA5].*$)([^(0-9a-zA-Z)]|[()]|[a-z]|[A-Z]|[0-9]){8,18}$/;
const loginRules = reactive({
  admin: [
    {
      required: true,
      message: "请输入帐号",
      trigger: "blur",
    },
  ],
  passWord: [
    {
      validator: (rule: any, value: any, callback: any) => {
        if (value === "") {
          callback(new Error("Please input the password"));
        } else if (!REGEXP_PWD.test(value)) {
          callback(new Error("密码应为8-18位数字、字母、符号的任意两种组合"));
        } else {
          callback();
        }
      },
    },
  ],
  // identifyCode: [
  //   {
  //     validator: (rule: any, value: any, callback: any) => {
      
  //       if (value === "") {
  //         callback(new Error("请输入验证码"));
  //       } else if (useUserStore().identifyCode !== value) {
  //         callback(new Error("验证码输入错误"));
  //       } else {
  //         callback();
  //       }
  //     },
  //   },
  // ],
});

export { loginRules };
